package com.cms.web.queryAnalyse;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.persistence.qxgl.beans.SYSUser;
import com.persistence.qxgl.beans.SYSYwxt;
import com.pub.SYSConstant;
import com.service.qxgl.SYSSecurityMgr;
import com.service.qxgl.SYSUserServiceMgr;
import com.web.BaseController;

import com.cms.biz.pending.CMSPendingServiceMgr;
import com.efounder.eai.data.JParamObject;
import com.efounder.eai.data.JResponseObject;

@Controller
@RequestMapping(value="/cmsPendingQueryAnalyse")
public class EMPCMSPendingQueryAnalyseController extends BaseController{
	@Autowired
	private                     CMSPendingServiceMgr                              pendingService;
	
	@Autowired
	private                        SYSUserServiceMgr                                     userMgr;
	
	@Autowired
	public                            SYSSecurityMgr                                 securityMgr;
	
	@Autowired
	public HttpSession session;

	/**
	 * 获取代办任务
	 * @param F_CKBH
	 * @param model
	 * @return
	 */
	@RequestMapping("/queryPendingData")
	public ModelAndView queryPendingData(@RequestParam String USER_ID, @RequestParam String USER_PASSWORD, Model model) {
		JParamObject          PO = JParamObject.Create();
		JResponseObject       RO = new JResponseObject();
		SYSUser             user = null;
		int          loginResult = -1;
		List<SYSYwxt>   ywxtList = new ArrayList<SYSYwxt>();
		ModelAndView         mav = new ModelAndView("ajaxDone");
		
		try {
			loginResult = userMgr.hasMatchUser(USER_ID, USER_PASSWORD);
		
			if(loginResult == SYSConstant.LOGIN_USER_NOTEXISTS) {
				RO.setErrorCode(-1);
				RO.setAddinObject("用户名不存。");
				return mav;
			} else if(loginResult == SYSConstant.LOGIN_PWD_WRONG) {
				RO.setErrorCode(-1);
				RO.setAddinObject("密码错误。");
				return mav;
			} else {
				user = userMgr.loadUserById(USER_ID);
				ywxtList = securityMgr.queryUserYwxt(USER_ID);
				
				for(int i = 0; i < ywxtList.size(); i++) {
					if(ywxtList.get(i).toString().equals("CMS")) {
						PO.SetValueByParamName("CXFLAG", "ALL");
						PO.SetValueByParamName("USER_ID", USER_ID);
						PO.SetValueByParamName("USER_ORGID", user.getUSER_ORGID());
						RO = pendingService.loadPendingFlow(PO);
						String pendFlowData = RO.getResponseObject().toString();
						RO.setAddinObject(pendFlowData);
						return mav;
					}
				}
				return mav;
			}
		} catch(Exception ce) {
			
		}
		return mav;
	}
}
